<?php

   class Company extends database_object{
        
        public $id;
        public $name;
        public $description;
        public $zipcode;
        
        protected static $table_name = "bo_company";
        protected static $db_fields  = array("id", "name", "description", "zipcode");
        
        // Method builds a company object
        public function build($cregistercompany="", $zipcode=0){
            
            if(!self::companyExists($cregistercompany)){
                $company            = new Company();
                $company->name      = $cregistercompany;
                $company->zipcode   = $zipcode;
                $company->create();
               
                return $company;
                
            }else{
                return false;
            }
                
        }
        
        //Method checks wether the companyname exists or not. Returns false if it does exist and true if not
        public function companyExists($ffname=""){
            $database = Database::getInstance();
            $name=  $database->escape_value($ffname);
            $sql = "SELECT * FROM " . self::$table_name;
            $sql .= " WHERE name= '{$ffname}' ;";

            $result_array = self::find_by_sql($sql);
               
            return !empty($result_array) ? array_shift($result_array) : false;
        }

        // Method that returns the name of the company
        public function toString()
        {
            return $this->name;
        }
        
    }
    $company = new Company();
?>
